from django.urls import path
from rest_framework.routers import DefaultRouter

from apps.schedule.views.CalendarView import CalendarViewSet
from apps.schedule.views.EventView import EventViewSet
from apps.schedule.views.batch_create import batch_create_events
from apps.schedule.views.check_conflicts import check_events_conflicts
from apps.schedule.views.process_schedule import process_schedule_draft

# 创建路由器
router = DefaultRouter()

# 注册视图集
router.register(r'events', EventViewSet, basename='event')
router.register(r'calendar', CalendarViewSet, basename='calendar')

# API 路由模式
urlpatterns = [
    # 日程基础功能路由
    path('events/', EventViewSet.as_view({
        'get': 'list',
        'post': 'create'
    }), name='event-list'),

    path('events/<int:pk>/', EventViewSet.as_view({
        'get': 'retrieve',
        'put': 'update',
        'patch': 'partial_update',
        'delete': 'destroy'
    }), name='event-detail'),

    # 日程特殊功能路由
    path('events/today/', EventViewSet.as_view({
        'get': 'today'
    }), name='event-today'),

    path('events/upcoming/', EventViewSet.as_view({
        'get': 'upcoming'
    }), name='event-upcoming'),
    
    path('events/date-range/', EventViewSet.as_view({
        'get': 'date_range'
    }), name='event-date-range'),

    path('events/<int:pk>/complete/', EventViewSet.as_view({
        'post': 'complete'
    }), name='event-complete'),

    # 日历功能路由
    path('calendar/', CalendarViewSet.as_view({
        'get': 'list'
    }), name='calendar-list'),

    path('calendar/<int:pk>/', CalendarViewSet.as_view({
        'get': 'retrieve'

    }), name='calendar-detail'),

    path('calendar/current-month/', CalendarViewSet.as_view({
        'get': 'current_month'
    }), name='calendar-current-month'),

    # AI处理、生成日程
    path('draft/process/', process_schedule_draft, name='process-schedule-draft'),

    # 批量生成日程
    path('events/batch/', batch_create_events, name='batch-create-events'),
    
    # 冲突检测相关路由
    path('events/check-conflicts/', check_events_conflicts, name='check-events-conflicts'),

    # AI 功能路由
    path('events/analyze-and-create/', EventViewSet.as_view({
        'post': 'analyze_and_create'
    }), name='event-analyze-create'),

    path('events/best-time/', EventViewSet.as_view({
        'post': 'best_time'
    }), name='event-best-time'),
]

